package com.zhentao.controller;

import com.zhentao.service.MinioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * MinIO测试控制器
 * 用于测试MinIO连接和存储桶创建
 * 
 * @author zhentao
 */
@RestController
@RequestMapping("/minio/test")
public class MinioTestController {

    @Autowired
    private MinioService minioService;

    @GetMapping("/connection")
    public Map<String, Object> testMinioConnection() {
        Map<String, Object> result = new HashMap<>();
        try {
            minioService.createBucket(); // 尝试创建桶，如果已存在则不创建
            result.put("success", true);
            result.put("message", "MinIO连接成功，存储桶'hyh'已存在或创建成功");
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "MinIO连接失败或存储桶创建失败: " + e.getMessage());
        }
        return result;
    }
}

